/*
 *  Copyright (c) 2009, Hugo Augusto Alves
 *  All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *      * Redistributions of source code must retain the above copyright
 *        notice, this list of conditions and the following disclaimer.
 *      * Redistributions in binary form must reproduce the above copyright
 *        notice, this list of conditions and the following disclaimer in the
 *        documentation and/or other materials provided with the distribution.
 *      * Neither the name of the Hugo Augusto Alves nor the
 *        names of its contributors may be used to endorse or promote products
 *        derived from this software without specific prior written permission.
 *
 *  THIS SOFTWARE IS PROVIDED BY COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
 *  EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 *  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 *  DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
 *  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 *  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 *  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */


/*
 * SettingsDialog.java
 *
 * Created on 13/11/2009, 21:28:43
 */
package org.wiscriptor.gui;

import java.util.ArrayList;
import org.wiscriptor.core.WiscriptorController;
import org.wiscriptor.internalization.I18N;
import org.wiscriptor.internalization.Language;

/**
 *
 * @author Hugo
 */
public class SettingsDialog extends javax.swing.JDialog {

    private WiscriptorController controller;
    private ArrayList<Language> langs;

    /** Creates new form SettingsDialog */
    public SettingsDialog(java.awt.Frame parent, boolean modal, WiscriptorController controller) {
        super(parent, modal);
        this.controller = controller;
        init();
    }

    private void init() {
        initComponents();
        langs = I18N.getInstance().getAvailableLanguages();
        for (Language l : langs) {
            langsComboBox.addItem(l.getName());
        }
    }

    public void reloadLabels() {
        generalLAFPane.setBorder(javax.swing.BorderFactory.createTitledBorder(I18N.getInstance().getValueForKey(I18N.key.settingslafTitle)));
        generalLangsPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(I18N.getInstance().getValueForKey(I18N.key.settingslangTitle)));
        tabbedPane.setTitleAt(0, I18N.getInstance().getValueForKey(I18N.key.settingsTab01));
        tabbedPane.setTitleAt(1, I18N.getInstance().getValueForKey(I18N.key.settingsTab02));
        tabbedPane.setTitleAt(2, I18N.getInstance().getValueForKey(I18N.key.settingsTab03));
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        tabbedPane = new javax.swing.JTabbedPane();
        mainPanel = new javax.swing.JPanel();
        generalLAFPane = new javax.swing.JPanel();
        lafComboBox = new javax.swing.JComboBox();
        lafBtn = new javax.swing.JButton();
        generalLangsPanel = new javax.swing.JPanel();
        langsComboBox = new javax.swing.JComboBox();
        langsBtn = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        tabbedPane.setTabPlacement(javax.swing.JTabbedPane.LEFT);

        generalLAFPane.setBorder(javax.swing.BorderFactory.createTitledBorder(I18N.getInstance().getValueForKey(I18N.key.settingslafTitle)));

        lafComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Autumn", "Business", "Business Black", "Business Blue", "Challenger", "Cremme", "Cremme Coffe", "Dust", "Dust Coffe", "Emerald", "Legacy", "Magma", "Mist Aqua", "Mist Silver", "Moderate", "Nebula", "Nebula Brick", "Office Blue", "Office Silver", "Raven", "Raven Glass", "Raven Graphite", "Twilight" }));

        lafBtn.setText(I18N.getInstance().getValueForKey(I18N.key.stringApply));
        lafBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                lafBtnActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout generalLAFPaneLayout = new javax.swing.GroupLayout(generalLAFPane);
        generalLAFPane.setLayout(generalLAFPaneLayout);
        generalLAFPaneLayout.setHorizontalGroup(
            generalLAFPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(generalLAFPaneLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lafComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 327, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(lafBtn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        generalLAFPaneLayout.setVerticalGroup(
            generalLAFPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(generalLAFPaneLayout.createSequentialGroup()
                .addGroup(generalLAFPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lafComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lafBtn))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        generalLangsPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(I18N.getInstance().getValueForKey(I18N.key.settingslangTitle)));

        langsComboBox.setMinimumSize(new java.awt.Dimension(95, 18));
        langsComboBox.setPreferredSize(new java.awt.Dimension(100, 20));

        langsBtn.setText(I18N.getInstance().getValueForKey(I18N.key.stringApply));
        langsBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                langsBtnActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout generalLangsPanelLayout = new javax.swing.GroupLayout(generalLangsPanel);
        generalLangsPanel.setLayout(generalLangsPanelLayout);
        generalLangsPanelLayout.setHorizontalGroup(
            generalLangsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(generalLangsPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(langsComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 327, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(langsBtn, javax.swing.GroupLayout.DEFAULT_SIZE, 135, Short.MAX_VALUE)
                .addContainerGap())
        );
        generalLangsPanelLayout.setVerticalGroup(
            generalLangsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(generalLangsPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(generalLangsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(langsComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(langsBtn))
                .addContainerGap(14, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(generalLangsPanel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(generalLAFPane, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(generalLAFPane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(generalLangsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(239, Short.MAX_VALUE))
        );

        tabbedPane.addTab(I18N.getInstance().getValueForKey(I18N.key.settingsTab01), mainPanel);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 532, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 392, Short.MAX_VALUE)
        );

        tabbedPane.addTab(I18N.getInstance().getValueForKey(I18N.key.settingsTab02), jPanel2);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 532, Short.MAX_VALUE)
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 392, Short.MAX_VALUE)
        );

        tabbedPane.addTab(I18N.getInstance().getValueForKey(I18N.key.settingsTab03), jPanel3);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(tabbedPane)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(tabbedPane, javax.swing.GroupLayout.DEFAULT_SIZE, 397, Short.MAX_VALUE)
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-671)/2, (screenSize.height-435)/2, 671, 435);
    }// </editor-fold>//GEN-END:initComponents

    private void lafBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_lafBtnActionPerformed
        controller.setLAF((String) lafComboBox.getSelectedItem());
        this.repaint();
    }//GEN-LAST:event_lafBtnActionPerformed

    private void langsBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_langsBtnActionPerformed
        Language l = langs.get(langsComboBox.getSelectedIndex());
        controller.changeLanguage(l.getLang(), l.getCountry());
    }//GEN-LAST:event_langsBtnActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel generalLAFPane;
    private javax.swing.JPanel generalLangsPanel;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JButton lafBtn;
    private javax.swing.JComboBox lafComboBox;
    private javax.swing.JButton langsBtn;
    private javax.swing.JComboBox langsComboBox;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JTabbedPane tabbedPane;
    // End of variables declaration//GEN-END:variables
}
